document.getElementById('btn1').addEventListener('click', function () {
    // 读取 html
    alert(editor.txt.html())
}, false)

document.getElementById('btn2').addEventListener('click', function () {
    // 读取 text
    alert(editor.txt.text())
}, false)

document.getElementById('fabu').addEventListener('click', function () {
    // 发布
    let title=document.querySelector('#titile_input').value.trim();
    // let titleflag=title.trim();
    if (title) {
        release(editor.txt.text(),editor.txt.html(),title)
    }else{
        alert("标题必须写")
    }


}, false)

function  release(text,htmltext,title) {
    let u_id= JSON.parse(localStorage.getItem("u_id"))

    let imgSrcS=imgUrl(htmltext)
    imgSrcS=JSON.stringify(imgSrcS)
    future.ajax({
        url:'/article/release',
        type:'post',
        data:{
            text,
            htmltext,
            u_id,
            imgSrcS: imgSrcS,
            title
        },
        success:function (result) {
            alert("发布成功,返回主页面")
            window.location.href = "../../oldHome.html"
            console.log(result)
        }
    })

}
/**
 * 截取html文本中img属性
 * @param string
 * @returns {Array}
 */
function imgUrl(string) {
    var a = string;
    var arrimg = [];
    a.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
        arrimg.push(capture);
    });
    if (arrimg != null && arrimg.length > 0) {
        return arrimg;
    }
}